package com.zhilianbao.leyaogo.ui.activity.me.setting;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.bql.commonrow.widget.DelayButton;
import com.bql.utils.CheckUtils;
import com.zhilianbao.leyaogo.R;
import com.zhilianbao.leyaogo.ui.activity.base.BaseOkHttpActivity;
import com.zhilianbao.leyaogo.utils.XToastUtils;

import butterknife.BindView;
import butterknife.OnClick;

public class ChangePhoneNumActivity extends BaseOkHttpActivity {

    @BindView(R.id.et_input_phone)
    EditText mEtInputPhone;
    @BindView(R.id.get_check_num)
    DelayButton mGetCheckNum;
    @BindView(R.id.et_input_check_num)
    EditText mEtInputCheckNum;
    @BindView(R.id.tv_chang_phone_commit)
    TextView mTvChangPhoneCommit;

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_chang_phone_num;
    }

    @Override
    protected void initViewsAndEvents(Bundle savedInstanceState) {
        initToolbarWithLeftText(getString(R.string.change_phone_num), getString(R.string.back));
    }


    @OnClick({R.id.get_check_num, R.id.tv_chang_phone_commit})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.get_check_num:
                final String newPhone = mEtInputPhone.getText().toString().trim();
                if (CheckUtils.isEmpty(newPhone)) {
                    XToastUtils.showShortToast(getString(R.string.input_phone_number));
                } else {
                    //                    if (CheckUtils.isMobilePhone(newPhone)) {
                    //                        AccountApi.verifyCellPhone(this, "0", newPhone, new JsonCallback<String>(String.class) {
                    //                            @Override
                    //                            public void onResponse(boolean isFromCache, String o, Request request, @Nullable Response response) {
                    //                                if (o.equals(HttpConfig.MSG_CODE_412 + "")) {
                    //                                    sendVerifyCode(newPhone, mGetCheckNum);
                    //                                } else if (o.equals(HttpConfig.MSG_CODE_413 + "")) {
                    //                                    XToastUtils.showShortToast(getString(R.string.phone_number_bind));
                    //                                }
                    //                            }
                    //                        });
                    //                    } else {
                    //                        XToastUtils.showShortToast(getString(R.string.wrong_phone_number));
                    //                    }
                }
                break;
            case R.id.tv_chang_phone_commit:
                String phoneNum = mEtInputPhone.getText().toString().trim();
                String checkNum = mEtInputCheckNum.getText().toString().trim();
                if (!CheckUtils.isEmpty(phoneNum) && !CheckUtils.isEmpty(checkNum)) {
                    //                    AccountApi.updateMobile(this, phoneNum, checkNum, "0", "0", new DialogCallback<Object>(this, Object.class) {
                    //                        @Override
                    //                        public void onResponse(boolean isFromCache, Object o, Request request, @Nullable Response response) {
                    //                            XToastUtils.showShortToast(getString(R.string.update_phone_number_suc));
                    //                            Utils.updateMobile(phoneNum);
                    //                            EventBus.getDefault().post(new EventManager(UserEventCode.MSG_CODE_MODIFY_MOBILE));
                    //                            pop();
                    //                        }
                    //                    });
                } else {
                    XToastUtils.showShortToast(getString(R.string.phone_number_or_verify_code_can_not_be_blank));
                }
                break;
        }
    }

    /**
     * 发送验证码请求
     */
    private void sendVerifyCode(String mobile, final DelayButton button) {
        //        AccountApi.sendVerifyCode(this, mobile, new JsonCallback<Object>(Object.class) {
        //            @Override
        //            public void onResponse(boolean isFromCache, Object o, Request request, @Nullable Response response) {
        //                XToastUtils.showShortToast(getString(R.string.send_verify_code_suc));
        //                button.startCountDown();
        //            }
        //        });
    }
}
